/**
 * 
 */
package lt.vin.exaatto.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.layout.client.Layout.AnimationCallback;
import com.google.gwt.layout.client.Layout.Layer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Vincentas
 *
 */
public class Resizer extends Composite {

	private static ResizerUiBinder uiBinder = GWT.create(ResizerUiBinder.class);

	interface ResizerUiBinder extends UiBinder<Widget, Resizer> {
	}

	@UiField
	LayoutPanel panel;
	
	@UiField
	Button button;
	
	boolean big = false;
	
	public Resizer(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));
		button.setText(firstName);
	}

	@UiHandler("button")
	void onClick(ClickEvent e) {		
		panel.forceLayout();
		if (big) {
			panel.setWidgetTopBottom(button, 10, Unit.PCT, 10, Unit.PCT);
		} else {
			panel.setWidgetTopBottom(button, -10, Unit.PCT, -10, Unit.PCT);
		}

		big = !big;
		button.setEnabled(false);
		panel.animate(1000, new AnimationCallback() {
			
			@Override
			public void onLayout(Layer layer, double progress) {
				
			}
			
			@Override
			public void onAnimationComplete() {
				button.setEnabled(true);
			}
		});	
	}

}
